home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / accounts / acct-1.3 / acct-1 / acct-1.3.73 / kernel_diffs-1.2.0 next >
Text File  |  1995-03-07  |  9KB  |  282 lines

  1. diff -ru --new-file linux/arch/i386/kernel/signal.c linux-1.2.0/arch/i386/kernel/signal.c
  2. --- linux/arch/i386/kernel/signal.c    Tue Feb  7 11:56:41 1995
  3. +++ linux-1.2.0/arch/i386/kernel/signal.c    Wed Mar  8 06:30:26 1995
  4. @@ -208,6 +208,7 @@
  5.                  /* fall through */
  6.              default:
  7.                  current->signal |= _S(signr & 0x7f);
  8. +                current->flags |= PF_SIGNALED;
  9.                  do_exit(signr);
  10.              }
  11.          }
  12. diff -ru --new-file linux/fs/exec.c linux-1.2.0/fs/exec.c
  13. --- linux/fs/exec.c    Mon Jan 30 13:08:04 1995
  14. +++ linux-1.2.0/fs/exec.c    Wed Mar  8 06:30:26 1995
  15. @@ -212,6 +212,7 @@
  16.      if (!file.f_op->write)
  17.          goto close_coredump;
  18.      has_dumped = 1;
  19. +    current->flags |= PF_DUMPCORE;
  20.             strncpy(dump.u_comm, current->comm, sizeof(current->comm));
  21.      dump.u_ar0 = (struct pt_regs *)(((unsigned long)(&dump.regs)) - ((unsigned long)(&dump)));
  22.      dump.signal = signr;
  23. @@ -775,6 +776,7 @@
  24.      current->mm->mmap = NULL;
  25.      current->suid = current->euid = current->fsuid = bprm->e_uid;
  26.      current->sgid = current->egid = current->fsgid = bprm->e_gid;
  27. +     current->flags &= ~PF_FORKNOEXEC;
  28.      if (N_MAGIC(ex) == OMAGIC) {
  29.          do_mmap(NULL, 0, ex.a_text+ex.a_data,
  30.              PROT_READ|PROT_WRITE|PROT_EXEC,
  31. diff -ru --new-file linux/include/linux/acct.h linux-1.2.0/include/linux/acct.h
  32. --- linux/include/linux/acct.h    Thu Jan  1 02:00:00 1970
  33. +++ linux-1.2.0/include/linux/acct.h    Wed Mar  8 06:30:26 1995
  34. @@ -0,0 +1,29 @@
  35. +#ifndef __LINUX_ACCT_H
  36. +#define __LINUX_ACCT_H
  37. +
  38. +#define ACCT_COMM 16
  39. +
  40. +struct acct
  41. +{
  42. +    char    ac_comm[ACCT_COMM];    /* Accounting command name */
  43. +    time_t    ac_utime;        /* Accounting user time */
  44. +    time_t    ac_stime;        /* Accounting system time */
  45. +    time_t    ac_etime;        /* Accounting elapsed time */
  46. +    time_t    ac_btime;        /* Beginning time */
  47. +    uid_t    ac_uid;            /* Accounting user ID */
  48. +    gid_t    ac_gid;            /* Accounting group ID */
  49. +    dev_t    ac_tty;            /* controlling tty */
  50. +    char    ac_flag;        /* Accounting flag */
  51. +    long    ac_minflt;        /* Accounting minor pagefaults */
  52. +    long    ac_majflt;        /* Accounting major pagefaults */
  53. +    long    ac_exitcode;        /* Accounting process exitcode */
  54. +};
  55. +
  56. +#define AFORK    0001    /* has executed fork, but no exec */
  57. +#define ASU    0002    /* used super-user privileges */
  58. +#define ACORE    0004    /* dumped core */
  59. +#define AXSIG    0010    /* killed by a signal */
  60. +
  61. +#define AHZ     100
  62. +
  63. +#endif
  64. diff -ru --new-file linux/include/linux/kernel.h linux-1.2.0/include/linux/kernel.h
  65. --- linux/include/linux/kernel.h    Wed Jan  4 21:16:05 1995
  66. +++ linux-1.2.0/include/linux/kernel.h    Wed Mar  8 06:30:26 1995
  67. @@ -55,16 +55,9 @@
  68.      __attribute__ ((format (printf, 1, 2)));
  69.  
  70.  /*
  71. - * This is defined as a macro, but at some point this might become a
  72. - * real subroutine that sets a flag if it returns true (to do
  73. - * BSD-style accounting where the process is flagged if it uses root
  74. - * privs).  The implication of this is that you should do normal
  75. - * permissions checks first, and check suser() last.
  76. - *
  77.   * "suser()" checks against the effective user id, while "fsuser()"
  78.   * is used for file permission checking and checks against the fsuid..
  79.   */
  80. -#define suser() (current->euid == 0)
  81.  #define fsuser() (current->fsuid == 0)
  82.  
  83.  #endif /* __KERNEL__ */
  84. diff -ru --new-file linux/include/linux/sched.h linux-1.2.0/include/linux/sched.h
  85. --- linux/include/linux/sched.h    Tue Mar  7 14:38:48 1995
  86. +++ linux-1.2.0/include/linux/sched.h    Wed Mar  8 06:30:26 1995
  87. @@ -198,6 +198,10 @@
  88.                      /* Not implemented yet, only for 486*/
  89.  #define PF_PTRACED    0x00000010    /* set if ptrace (0) has been called. */
  90.  #define PF_TRACESYS    0x00000020    /* tracing system calls */
  91. +#define PF_FORKNOEXEC    0x00000040    /* forked but didn't exec */
  92. +#define PF_SUPERPREV    0x00000100    /* used super-user privileges */
  93. +#define PF_DUMPCORE    0x00000200    /* dumped core */
  94. +#define PF_SIGNALED    0x00000400    /* killed by a signal */
  95.  
  96.  #define PF_STARTING    0x00000100    /* being created */
  97.  #define PF_EXITING    0x00000200    /* getting shut down */
  98. @@ -268,6 +272,19 @@
  99.  extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
  100.      unsigned long flags, const char *device);
  101.  extern void free_irq(unsigned int irq);
  102. +
  103. +/*
  104. + * This has now become a routine instead of a macro, it sets a flag if
  105. + * it returns true (to do BSD-style accounting where the process is flagged
  106. + * if it uses root privs). The implication of this is that you should do
  107. + * normal permissions checks first, and check suser() last.
  108. + */
  109. +extern inline int suser(void)
  110. +{
  111. +    if (current->euid == 0)
  112. +        current->flags |= PF_SUPERPREV;
  113. +    return (current->euid == 0);
  114. +}
  115.  
  116.  extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
  117.  extern void flush_thread(void);
  118. diff -ru --new-file linux/kernel/exit.c linux-1.2.0/kernel/exit.c
  119. --- linux/kernel/exit.c    Tue Mar  7 14:41:56 1995
  120. +++ linux-1.2.0/kernel/exit.c    Wed Mar  8 06:32:40 1995
  121. @@ -18,6 +18,7 @@
  122.  
  123.  #include <asm/segment.h>
  124.  extern void sem_exit (void);
  125. +extern void acct_process (long exitcode);
  126.  
  127.  int getrusage(struct task_struct *, int, struct rusage *);
  128.  
  129. @@ -380,6 +381,7 @@
  130.          intr_count = 0;
  131.      }
  132.  fake_volatile:
  133. +    acct_process(code);
  134.      current->flags |= PF_EXITING;
  135.      sem_exit();
  136.      exit_mmap(current);
  137. diff -ru --new-file linux/kernel/fork.c linux-1.2.0/kernel/fork.c
  138. --- linux/kernel/fork.c    Wed Mar  1 13:31:54 1995
  139. +++ linux-1.2.0/kernel/fork.c    Wed Mar  8 06:30:26 1995
  140. @@ -188,7 +188,8 @@
  141.      p->kernel_stack_page = new_stack;
  142.      *(unsigned long *) p->kernel_stack_page = STACK_MAGIC;
  143.      p->state = TASK_UNINTERRUPTIBLE;
  144. -    p->flags &= ~(PF_PTRACED|PF_TRACESYS);
  145. +    p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV);
  146. +    p->flags |= PF_FORKNOEXEC;
  147.      p->pid = last_pid;
  148.      p->p_pptr = p->p_opptr = current;
  149.      p->p_cptr = NULL;
  150. diff -ru --new-file linux/kernel/sys.c linux-1.2.0/kernel/sys.c
  151. --- linux/kernel/sys.c    Sun Mar  5 00:16:36 1995
  152. +++ linux-1.2.0/kernel/sys.c    Wed Mar  8 06:30:27 1995
  153. @@ -17,6 +17,10 @@
  154.  #include <linux/stat.h>
  155.  #include <linux/mman.h>
  156.  #include <linux/mm.h>
  157. +#include <linux/fcntl.h>
  158. +#include <linux/acct.h>
  159. +#include <linux/tty.h>
  160. +#include <sys/sysmacros.h>
  161.  
  162.  #include <asm/segment.h>
  163.  #include <asm/io.h>
  164. @@ -235,10 +239,113 @@
  165.          return -EPERM;
  166.      return 0;
  167.  }
  168. -
  169. -asmlinkage int sys_acct(void)
  170. -{
  171. -    return -ENOSYS;
  172. +  
  173. +static char acct_active = 0;
  174. +static struct file acct_file;
  175. +
  176. +int acct_process(long exitcode)
  177. +{
  178. +   struct acct ac;
  179. +   unsigned short fs;
  180. +
  181. +   if (acct_active) {
  182. +      strncpy(ac.ac_comm, current->comm, ACCT_COMM);
  183. +      ac.ac_comm[ACCT_COMM] = '\0';
  184. +      ac.ac_utime = current->utime;
  185. +      ac.ac_stime = current->stime;
  186. +      ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
  187. +      ac.ac_etime = CURRENT_TIME - ac.ac_btime;
  188. +      ac.ac_uid   = current->uid;
  189. +      ac.ac_gid   = current->gid;
  190. +      ac.ac_tty   = (current)->tty == NULL ? -1 : 
  191. +         makedev (4, current->tty->device);
  192. +      ac.ac_flag  = 0;
  193. +      if (current->flags & PF_FORKNOEXEC)
  194. +         ac.ac_flag |= AFORK;
  195. +      if (current->flags & PF_SUPERPREV)
  196. +         ac.ac_flag |= ASU;
  197. +      if (current->flags & PF_DUMPCORE)
  198. +         ac.ac_flag |= ACORE;
  199. +      if (current->flags & PF_SIGNALED)
  200. +         ac.ac_flag |= AXSIG;
  201. +      ac.ac_minflt = current->mm->min_flt;
  202. +      ac.ac_majflt = current->mm->maj_flt;
  203. +      ac.ac_exitcode = exitcode;
  204. +
  205. +      /* Kernel segment override */
  206. +      fs = get_fs();
  207. +      set_fs(KERNEL_DS);
  208. +
  209. +      acct_file.f_op->write(acct_file.f_inode, &acct_file,
  210. +                             (char *)&ac, sizeof(struct acct));
  211. +
  212. +      set_fs(fs);
  213. +   }
  214. +   return 0;
  215. +}
  216. +
  217. +asmlinkage int sys_acct(const char *name)
  218. +{
  219. +   struct inode *inode = (struct inode *)0;
  220. +   char *tmp;
  221. +   int error;
  222. +
  223. +   if (!suser())
  224. +      return -EPERM;
  225. +
  226. +   if (name == (char *)0) {
  227. +      if (acct_active) {
  228. +         if (acct_file.f_op->release)
  229. +            acct_file.f_op->release(acct_file.f_inode, &acct_file);
  230. +
  231. +         if (acct_file.f_inode != (struct inode *) 0)
  232. +            iput(acct_file.f_inode);
  233. +
  234. +         acct_active = 0;
  235. +      }
  236. +      return 0;
  237. +   } else {
  238. +      if (!acct_active) {
  239. +
  240. +         if ((error = getname(name, &tmp)) != 0)
  241. +            return (error);
  242. +
  243. +         error = open_namei(tmp, O_RDWR, 0600, &inode, 0);
  244. +         putname(tmp);
  245. +
  246. +         if (error)
  247. +            return (error);
  248. +
  249. +         if (!S_ISREG(inode->i_mode)) {
  250. +            iput(inode);
  251. +            return -EACCES;
  252. +         }
  253. +
  254. +         if (!inode->i_op || !inode->i_op->default_file_ops || 
  255. +             !inode->i_op->default_file_ops->write) {
  256. +            iput(inode);
  257. +            return -EIO;
  258. +         }
  259. +
  260. +         acct_file.f_mode = 3;
  261. +         acct_file.f_flags = 0;
  262. +         acct_file.f_count = 1;
  263. +         acct_file.f_inode = inode;
  264. +         acct_file.f_pos = inode->i_size;
  265. +         acct_file.f_reada = 0;
  266. +         acct_file.f_op = inode->i_op->default_file_ops;
  267. +
  268. +         if (acct_file.f_op->open)
  269. +            if (acct_file.f_op->open(acct_file.f_inode, &acct_file)) {
  270. +               iput(inode);
  271. +               return -EIO;
  272. +            }
  273. +
  274. +         acct_active = 1;
  275. +         return 0;
  276. +      } else
  277. +         return -EBUSY;
  278. +   }
  279.  }
  280.  
  281.  asmlinkage int sys_phys(void)
  282.